/**
 * Description: 定义一个长度为10的整数数组，可用于保存用户通过控制台输入的10个整数，并计算它们的平均值、最大值、最小值
 * Class Name:subject1
 * Date:2022/2/24 12:20
 *
 * @author LTisme
 * @version JAVA17
 */
package 疯狂Java讲义.第7章_Java基础类库.课后练习;

import java.util.Arrays;
import java.util.Scanner;

public class subject1 {
    public double cal_average(int[] list){
        int sum = 0;
        for (var num :
                list) {
            sum += num;
        }
        return (double) sum/list.length;
    }

    public int cal_summary(int[] list){
        int sum = 0;
        for (var num :
                list) {
            sum += num;
        }
        return sum;
    }

    public int cal_maximum(int[] list){
        int max = list[0];
        for (int i = 1; i < list.length; i++) {
            if (max < list[i]) max = list[i];
        }
        return max;
    }

    public int cal_minmum(int[] list){
        int min = list[0];
        for (int i = 1; i < list.length; i++) {
            if (min > list[i]) min = list[i];
        }
        return min;
    }

    public static void main(String[] args) {
        var calulator = new subject1();
        int[] integer_list = new int[10];
        System.out.println("请输入10个整数，可一次输入多个，用空格隔开，也可一次输入一个用回车，直到输入10个整数。");
        var input = new Scanner(System.in);
        int length = 0;
        while (input.hasNextInt()){
            integer_list[length] = input.nextInt();
            ++length;
            if ( length< integer_list.length){
                System.out.println("请输入10个整数，您已输入" + length + "个，还剩" + (integer_list.length - length) + "个。");
            }
            else {
                System.out.println("您已输入10个整数：" + Arrays.toString(integer_list) + "-->下面将开始进行计算");
                break;
            }
        }
        System.out.println("平均值为：" + calulator.cal_average(integer_list));
        System.out.println("总和为：" + calulator.cal_summary(integer_list));
        System.out.println("最大值为：" + calulator.cal_maximum(integer_list));
        System.out.println("最小值为：" + calulator.cal_minmum(integer_list));
    }
}
